package com.ehaoyao.service.impl;

import com.ehaoyao.entity.Order;
import com.ehaoyao.repository.OrderRepository;
import com.ehaoyao.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <dl>
 * <dt>OrderServiceImpl</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2006</dd>
 * <dd>CreateDate: 2020/6/13</dd>
 * </dl>
 *
 * @author zhangyp
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderRepository orderRepository;


    @Override
    public void save(Order order) {
        orderRepository.save(order);
    }

    @Override
    public void update(Order order) {
        orderRepository.save(order);
    }

    @Override
    public void delete(Integer id) {
        orderRepository.deleteById(id);
    }

    @Override
    public List<Order> selectAll() {
        return orderRepository.findAll();
    }

    @Override
    public Order selectById(Integer id) {
        return orderRepository.findById(id).get();
    }

    @Override
    public List<Order> selectByParam(Order order) {
        ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("id","price");
        Example<Order> example = Example.of(order, matcher);
        return orderRepository.findAll(example);
    }
}
